
import numpy as np

class TemperatureAttentionController:
    """温度-注意力协同控制器"""
    def __init__(self, init_temp=0.8, decay_factor=0.95, entropy_threshold=0.1):
        self.temperature = init_temp
        self.decay_factor = decay_factor
        self.entropy_threshold = entropy_threshold
        
    def update_temperature(self, entropy_change_rate):
        """温度系数动态演化 (式8)"""
        if entropy_change_rate > self.entropy_threshold:
            self.temperature *= self.decay_factor  # 快速衰减
        else:
            self.temperature *= (1 + self.decay_factor)/2  # 缓慢回升
        return self.temperature
    
    def get_layer_weights(self, temp_state):
        """层间温度协调机制 (3.3节)"""
        if temp_state > 0.5:  # 高温态
            return [0.5, 0.33, 0.17]  # 3:2:1比例
        else:  # 低温态
            return [0.77, 0.15, 0.08]  # 5:1:0.5比例
